package com.smart.village.big.screen.controller.micro;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.smart.village.big.screen.domain.AjaxResult;
import com.smart.village.big.screen.domain.PartyMemberLogStaticVo;
import com.smart.village.big.screen.service.PartyFeesService;
import com.smart.village.big.screen.service.PartyOrganizationActivityService;
import com.smart.village.big.screen.service.PartyOrganizationApplicationService;
import com.smart.village.big.screen.service.PartyOrganizationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;

import static com.smart.village.big.screen.domain.AjaxResult.error;
import static com.smart.village.big.screen.domain.AjaxResult.success;


/**
 * 小程序-党组织情况
 */
@Tag(name = "小程序-党组织情况接口")
@RestController
@RequestMapping("/micro/party/organization")
public class MicroPartyOrganizationController {
    Logger logger = Logger.getLogger(MicroPartyOrganizationController.class.getName());

    @Autowired
    private PartyOrganizationActivityService partyOrganizationActivityService;
    @Autowired
    private PartyOrganizationApplicationService partyOrganizationApplicationService;
    @Autowired
    private PartyFeesService partyFeesService;
    @Autowired
    private PartyOrganizationService partyOrganizationService;


    /**
     * 小程序 三会一课
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "小程序 三会一课，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取三会一课列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委"),
            @Parameter(name = "activityStatus", description = "活动状态"),
            @Parameter(name = "activityType", description = "活动类别"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getThreeMeetingsOneLectureList")
    @ResponseBody
    public AjaxResult getThreeMeetingsOneLectureList(@RequestParam(required = false) String formatDate,
                                                     @RequestParam(required = false) String partyOrganizationSerialNumber,
                                                     @RequestParam(required = false) String activityStatus,
                                                     @RequestParam(required = false) String activityType,
                                                     @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                     @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            if (StringUtils.isEmpty(activityType)) {
                activityTypeList.add("党员大会");
                activityTypeList.add("党小组会");
                activityTypeList.add("支委会");
                activityTypeList.add("党课");
            } else {
                if (activityType.equals("党员大会")) {
                    activityTypeList.add("党员大会");
                }
                if (activityType.equals("党小组会")) {
                    activityTypeList.add("党小组会");
                }
                if (activityType.equals("支委会")) {
                    activityTypeList.add("支委会");
                }
                if (activityType.equals("党课")) {
                    activityTypeList.add("党课");
                }
            }

            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }
            return success(partyOrganizationActivityService
                    .getMicroPartyOrganizationActivityListByStatus
                            (formatDate,
                                    partyOrganizationSerialNumber,
                                    activityTypeList,
                                    activityStatus,
                                    "支部", pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 主题党日
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "小程序 主题党日，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取 主题党日列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委"),
            @Parameter(name = "activityStatus", description = "活动状态"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getTopicPartyDayList")
    @ResponseBody
    public AjaxResult getTopicPartyDayList(@RequestParam(required = false) String formatDate,
                                           @RequestParam(required = false) String partyOrganizationSerialNumber,
                                           @RequestParam(required = false) String activityStatus,
                                           @RequestParam(required = false, defaultValue = "1") int pageNum,
                                           @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        try {
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }
            List<String> activityTypeList = Lists.newArrayList();
            activityTypeList.add("主题党日");
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            return success(partyOrganizationActivityService
                    .getMicroPartyOrganizationActivityListByStatus
                            (formatDate,
                                    partyOrganizationSerialNumber,
                                    activityTypeList,
                                    activityStatus,
                                    "支部", pageNum, pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 双联系双报到
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "小程序 双联系双报到，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取 主题党日列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委"),
            @Parameter(name = "activityStatus", description = "活动状态"),
            @Parameter(name = "iDCardNumber", description = "身份证"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getTwoContactTwoReport")
    @ResponseBody
    public AjaxResult getTwoContactTwoReport(@RequestParam(required = false) String formatDate,
                                             @RequestParam(required = false) String partyOrganizationSerialNumber,
                                             @RequestParam String activityStatus,
                                             @RequestParam String iDCardNumber,
                                             @RequestParam(required = false, defaultValue = "1") int pageNum,
                                             @RequestParam(required = false, defaultValue = "10") int pageSize) {
        try {
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }
            List<String> activityTypeList = Lists.newArrayList();
            activityTypeList.add("双联系双报到");
            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            return success(partyOrganizationActivityService
                    .getMicroTwoContactTwoReport
                            (formatDate,
                                    partyOrganizationSerialNumber,
                                    activityTypeList,
                                    activityStatus,
                                    iDCardNumber,
                                    "支部", pageNum, pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 活动详情
     *
     * @param partyOrganizationActivitySerialNumber
     * @return
     */
    @Operation(summary = "小程序 活动详情")
    @Parameters({
            @Parameter(name = "partyOrganizationActivitySerialNumber", description = "主键"),
    })
    @GetMapping("/activity/detail")
    @ResponseBody
    public AjaxResult getMicroPartyOrganizationActivitiesStaticVoDetail(@RequestParam String partyOrganizationActivitySerialNumber) {
        return success(partyOrganizationActivityService.getMicroPartyOrganizationActivitiesStaticVoDetail(partyOrganizationActivitySerialNumber));
    }

    /**
     * 小程序 活动 报名
     *
     * @param partyOrganizationActivitySerialNumber
     * @param iDCardNumber
     * @return
     */
    @Operation(summary = "小程序 活动 报名")
    @Parameters({
            @Parameter(name = "partyOrganizationActivitySerialNumber", description = "主键"),
            @Parameter(name = "iDCardNumber", description = "身份证号"),
    })
    @GetMapping("/activity/microActivitySignUp")
    @ResponseBody
    public AjaxResult microActivitySignUp(
            @RequestParam String partyOrganizationActivitySerialNumber,
            @RequestParam String iDCardNumber
    ) {
        int i = partyOrganizationActivityService.microActivitySignUp(partyOrganizationActivitySerialNumber, iDCardNumber);
        if(i > 0) {
            return success("报名成功",i);
        }else{
            return error("报名失败",i);
        }
    }

    /**
     * 小程序 根据年份和 党员id获取党费缴纳信息
     *
     * @return
     */
    @Operation(summary = "小程序 根据年份和 党员id获取党费缴纳信息")
    @Parameters({
            @Parameter(name = "year", description = ""),
            @Parameter(name = "partyMemberSerialNumber", description = "党员id")
    })
    @GetMapping("getPartyFeesByPartyMemberAndYear")
    @ResponseBody
    public AjaxResult getPartyFeesByPartyMemberAndYear(
            @RequestParam String year,
            @RequestParam String partyMemberSerialNumber
    ) {
        try {
            HashMap param = new HashMap();
            param.put("year",year);
            param.put("partyMemberSerialNumber",partyMemberSerialNumber);
            return success(partyFeesService.getPartyFeesByPartyMemberAndYear(param));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }
    /**
     * 小程序 根据年份和 党员id获取党费缴纳 列表
     *
     * @return
     */
    @Operation(summary = "小程序 根据年份和 党员id获取党费缴纳 列表")
    @Parameters({
            @Parameter(name = "year", description = ""),
            @Parameter(name = "partyMemberSerialNumber", description = "党员id")
    })
    @GetMapping("getPartyFeesDetailByPartyMemberAndYear")
    @ResponseBody
    public AjaxResult getPartyFeesDetailByPartyMemberAndYear(
            @RequestParam String year,
            @RequestParam String partyMemberSerialNumber
    ) {
        try {
            HashMap param = new HashMap();
            param.put("year",year);
            param.put("partyMemberSerialNumber",partyMemberSerialNumber);
            return success(partyFeesService.getPartyFeesDetailByPartyMemberAndYear(param));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 组织管理接口
     * @param partyOrganizationSerialNumber
     * @return
     */
    @Operation(summary = "小程序 组织管理接口")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "选择的党组织"),
    })
    @GetMapping("/getMicroPartyOrganizationManager")
    @ResponseBody
    public AjaxResult getMicroPartyOrganizationManager(
            @RequestParam String partyOrganizationSerialNumber
    ){
        return success(partyOrganizationService.getMicroPartyOrganizationManager(partyOrganizationSerialNumber));
    }

    /**
     * 小程序 组织结构树
     * @param partyOrganizationSerialNumber
     * @return
     */
    @Operation(summary = "小程序 组织结构树")
    @Parameters({
            @Parameter(name = "partyOrganizationSerialNumber", description = "选择的党组织"),
    })
    @GetMapping("/getMicroPartyOrganizationTree")
    @ResponseBody
    public AjaxResult getMicroPartyOrganizationTree(
            @RequestParam String partyOrganizationSerialNumber
    ){
        return success(partyOrganizationService.getMicroPartyOrganizationTree(partyOrganizationSerialNumber));
    }


    /**
     * 小程序 账户信息
     * @param openld
     * @return
     */
    @Operation(summary = "小程序 账户信息")
    @Parameters({
            @Parameter(name = "openld", description = "openld"),
    })
    @GetMapping("/getMicroAccountInformation")
    @ResponseBody
    public AjaxResult getMicroAccountInformation(
            @RequestParam String openld
    ){
        return success(partyOrganizationService.getMicroAccountInformation(openld));
    }

    /**
     * 小程序 党员档案
     * @param iDCardNumber
     * @return
     */
    @Operation(summary = "小程序 党员档案")
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号"),
    })
    @GetMapping("/getMicroPartyMemberInformation")
    @ResponseBody
    public AjaxResult getMicroPartyMemberInformation(
            @RequestParam String iDCardNumber
    ){
        return success(partyOrganizationService.getMicroPartyMemberInformation(iDCardNumber));
    }

    /**
     * 小程序 党员档案 事件情况 type 0 成长轨迹 1 奖惩情况
     * @param partyMemberSerialNumber
     * @return
     */
    @Operation(summary = "小程序 党员档案 事件情况")
    @Parameters({
            @Parameter(name = "partyMemberSerialNumber", description = "党员id"),
            @Parameter(name = "type", description = "类型 0 成长轨迹 1 奖惩情况，默认1 奖惩"),
    })
    @GetMapping("/getMicroPartyMemberEvent")
    @ResponseBody
    public AjaxResult getMicroPartyMemberEvent(
            @RequestParam String partyMemberSerialNumber,
            @RequestParam(defaultValue = "1",required = false) String type,
            @RequestParam(defaultValue = "1",required = false) int pageNum,
            @RequestParam(defaultValue = "10",required = false) int pageSize
    ){
        return success(partyOrganizationService.getMicroPartyMemberEvent(partyMemberSerialNumber,type,pageNum,pageSize));
    }



    /**
     * 小程序 入党材料接口-判断是否存在党员申请
     *
     * @return
     */
    @Operation(summary = "小程序 入党材料接口 判断是否存在党员申请")
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号")
    })
    @GetMapping("getIfExistPartyOrganizationApplication")
    @ResponseBody
    public AjaxResult getIfExistPartyOrganizationApplication(
            @RequestParam String iDCardNumber) {
        try {
            String ifExistPartyOrganizationApplication = partyOrganizationApplicationService.getIfExistPartyOrganizationApplication(iDCardNumber);
            JSONObject jsonObject = new JSONObject();
            if (StringUtils.isNotBlank(ifExistPartyOrganizationApplication)) {
                jsonObject.put("applicationSerialNumber",ifExistPartyOrganizationApplication);
                jsonObject.put("status","1");
            }else{
                jsonObject.put("applicationSerialNumber","");
                jsonObject.put("status","0");
            }

            return success(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 入党材料接口
     *
     * @return
     */
    @Operation(summary = "小程序 入党材料接口")
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号")
    })
    @GetMapping("getMicroPartyMemberLogStaticDetail")
    @ResponseBody
    public AjaxResult getMicroPartyMemberLogStaticDetail(
            @RequestParam String iDCardNumber) {
        try {
            List<PartyMemberLogStaticVo> resultJson = partyOrganizationApplicationService.getMicroPartyMemberLogStaticDetail(iDCardNumber);
            return success(resultJson);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 查询 是否实名
     * @param name
     * @param iDCardNumber
     * @return
     */
    @Operation(summary = "小程序 查询 是否实名")
    @Parameters({
            @Parameter(name = "name", description = "姓名"),
            @Parameter(name = "iDCardNumber", description = "身份证"),
    })
    @GetMapping("/getMicroIfRealCheck")
    @ResponseBody
    public AjaxResult getMicroIfRealCheck(
            @RequestParam String name,
            @RequestParam String iDCardNumber
    ){
        return success(partyOrganizationService.getMicroIfRealCheck(name,iDCardNumber));
    }


    /**
     * 小程序 获取活动资料上报 列表
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "小程序 获取活动资料上报 列表")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委"),
            @Parameter(name = "uploadStatus", description = "材料上报状态"),
            @Parameter(name = "activityType", description = "活动类别"),
            @Parameter(name = "phone", description = "用户id"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getMicroPartyOrganizationActivitiesUploadList")
    @ResponseBody
    public AjaxResult getMicroPartyOrganizationActivitiesUploadList(@RequestParam(required = false) String formatDate,
                                                     @RequestParam(required = false) String partyOrganizationSerialNumber,
                                                     @RequestParam(required = false) String uploadStatus,
                                                     @RequestParam(required = false) String activityType,
                                                     @RequestParam String phone,
                                                     @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                     @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            if (StringUtils.isEmpty(activityType)) {
                activityTypeList.add("党员大会");
                activityTypeList.add("党小组会");
                activityTypeList.add("支委会");
                activityTypeList.add("党课");
                activityTypeList.add("双联系双报到");
                activityTypeList.add("主题党日");
                activityTypeList.add("民主生活会");
                activityTypeList.add("组织生活会");
            } else {
                if (activityType.equals("党员大会")) {
                    activityTypeList.add("党员大会");
                }
                if (activityType.equals("党小组会")) {
                    activityTypeList.add("党小组会");
                }
                if (activityType.equals("支委会")) {
                    activityTypeList.add("支委会");
                }
                if (activityType.equals("党课")) {
                    activityTypeList.add("党课");
                }
                if (activityType.equals("双联系双报到")) {
                    activityTypeList.add("双联系双报到");
                }
                if (activityType.equals("主题党日")) {
                    activityTypeList.add("主题党日");
                }
                if (activityType.equals("民主生活会")) {
                    activityTypeList.add("民主生活会");
                }
                if (activityType.equals("组织生活会")) {
                    activityTypeList.add("组织生活会");
                }
            }

            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }
            return success(partyOrganizationActivityService
                    .getMicroPartyOrganizationActivitiesUploadList
                            (formatDate,
                                    partyOrganizationSerialNumber,
                                    activityTypeList,
                                    uploadStatus,
                                    "支部",phone, pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 获取活动资料上报 详情
     * @param phone
     * @param partyOrganizationActivitySerialNumber
     * @return
     */
    @Operation(summary = "小程序 获取活动资料上报 详情")
    @Parameters({
            @Parameter(name = "phone", description = "用户id"),
            @Parameter(name = "partyOrganizationActivitySerialNumber", description = "活动id"),
    })
    @GetMapping("/activity/getMicroPartyOrganizationActivitiesUploadDetail")
    @ResponseBody
    public AjaxResult getMicroPartyOrganizationActivitiesUploadDetail(
            @RequestParam String phone,
            @RequestParam String partyOrganizationActivitySerialNumber
    ){

        return success(partyOrganizationActivityService.getMicroPartyOrganizationActivitiesUploadDetail(phone,partyOrganizationActivitySerialNumber));
    }

    /**
     * 小程序 红色教育基地
     * @param search
     * @return
     */
    @Operation(summary = "小程序 红色教育基地")
    @GetMapping("/getMicroRedEducationBase")
    @ResponseBody
    public AjaxResult getMicroRedEducationBase(
            @RequestParam(required = false) @Parameter(description = "搜索") String search
    ){
        return success(partyOrganizationService.getMicroBluePlateInformationListByTagSerialNumber("BPT000000000006",search));
    }



    /**
     * 小程序 获取活动签到 详情
     * @param partyOrganizationActivitySerialNumber
     * @return
     */
    @Operation(summary = "小程序 获取活动签到 详情")
    @Parameters({
            @Parameter(name = "partyOrganizationActivitySerialNumber", description = "活动id"),
    })
    @GetMapping("/activity/getMicroPartyOrganizationActivitiesCheckDetail")
    @ResponseBody
    public AjaxResult getMicroPartyOrganizationActivitiesCheckDetail(
            @RequestParam String partyOrganizationActivitySerialNumber
    ){

        return success(partyOrganizationActivityService.getMicroPartyOrganizationActivitiesCheckDetail(partyOrganizationActivitySerialNumber));
    }


    /**
     * 小程序 组织管理-组织任务
     *
     * @return
     */
    @Operation(summary = "小程序 组织管理-组织任务")
    @Parameters({
            @Parameter(name = "type", description = "任务类型"),
            @Parameter(name = "iDCardNumber", description = "身份证号"),
            @Parameter(name = "status", description = "当前状态"),
            @Parameter(name = "year", description = "缴费年度 只有查看缴费任务的时候才传"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
        @GetMapping("/activity/getMicroOrgTask")
    @ResponseBody
    public AjaxResult getMicroOrgTask(
                                             @RequestParam String iDCardNumber,
                                             @RequestParam(required = false) String type,
                                             @RequestParam(required = false)  String status,
                                             @RequestParam(required = false)  String year,
                                             @RequestParam(required = false, defaultValue = "1") int pageNum,
                                             @RequestParam(required = false, defaultValue = "10") int pageSize) {
        try {
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }

            return success(partyOrganizationActivityService
                    .getMicroOrgTask(
                                    type,
                                    iDCardNumber,status,year,
                                     pageNum, pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 组织管理-组织任务-类型
     *
     * @return
     */
    @Operation(summary = "小程序 组织管理-组织任务-类型")
    @Parameters({

    })
        @GetMapping("/activity/getMicroOrgTaskTypeList")
    @ResponseBody
    public AjaxResult getMicroOrgTaskTypeList() {
        try {


            return success(partyOrganizationActivityService
                    .getMicroOrgTaskTypeList()
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 组织管理-组织任务-帮扶详情
     *
     * @return
     */
    @Operation(summary = "小程序 组织管理-组织任务-帮扶详情")
    @Parameters({
            @Parameter(name = "type", description = "任务类型"),
            @Parameter(name = "id", description = "任务id")
    })
    @GetMapping("/activity/getMicroOrgTaskDetail")
    @ResponseBody
    public AjaxResult getMicroOrgTaskDetail(
            @RequestParam String type,
            @RequestParam String id) {
        try {
            return success(partyOrganizationActivityService
                    .getMicroOrgTaskDetail(
                            type,
                            id)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 组织管理-组织任务-根据帮扶任务id获取帮扶日志
     *
     * @return
     */
    @Operation(summary = "小程序 组织管理-组织任务-根据帮扶任务id获取帮扶日志")
    @Parameters({
            @Parameter(name = "assistanceSerialNumber", description = "帮扶id"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getMicroAssistanceLog")
    @ResponseBody
    public AjaxResult getMicroAssistanceLog(
            @RequestParam  String assistanceSerialNumber,   @RequestParam(required = false, defaultValue = "1") int pageNum,
            @RequestParam(required = false, defaultValue = "10") int pageSize) {
        try {
            return success(partyOrganizationActivityService
                    .getMicroAssistanceLog(
                            assistanceSerialNumber,pageNum,pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 组织管理-组织任务-根据帮扶日志id获取帮扶回访
     *
     * @return
     */
    @Operation(summary = "小程序 组织管理-组织任务-根据帮扶日志id获取帮扶回访")
    @Parameters({
            @Parameter(name = "assistanceLogSerialNumber", description = "日志id"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getMicroAssistanceReturn")
    @ResponseBody
    public AjaxResult getMicroAssistanceReturn(
            @RequestParam  String assistanceLogSerialNumber   ,@RequestParam(required = false, defaultValue = "1") int pageNum,
    @RequestParam(required = false, defaultValue = "10") int pageSize) {
        try {
            return success(partyOrganizationActivityService
                    .getMicroAssistanceReturn(
                            assistanceLogSerialNumber,pageNum,pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 个人中心党员端-驻村工作队-介绍
     *
     * @return
     */
    @Operation(summary = "小程序 个人中心党员端-驻村工作队-介绍")
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号 非必填"),
            @Parameter(name = "workTeamSerialNumber", description = "工作队id 非必填，党组的接口中需要传"),
    })
    @GetMapping("/work/teams")
    @ResponseBody
    public AjaxResult getWorkTeams(
            @RequestParam(required = false)  String iDCardNumber,
            @RequestParam(required = false)  String workTeamSerialNumber
            ) {
        try {
            return success(partyOrganizationActivityService
                    .getWorkTeams(
                            iDCardNumber,workTeamSerialNumber)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 个人中心党员端-驻村工作队-工作情况
     *
     * @return
     */
    @Operation(summary = "小程序 个人中心党员端-驻村工作队-工作情况")
    @Parameters({
            @Parameter(name = "yearMonth", description = "年份-月份 例如 2025-06"),
            @Parameter(name = "iDCardNumber", description = "身份证号"),
            @Parameter(name = "workTeamSerialNumber", description = "工作队id"),
    })
    @GetMapping("/work/teams/logs")
    @ResponseBody
    public AjaxResult getWorkTeamsLogs(
            @RequestParam(required = false)  String yearMonth,
            @RequestParam  String iDCardNumber,
            @RequestParam  String workTeamSerialNumber
            ) {
        try {
            return success(partyOrganizationActivityService
                    .getWorkTeamsLogs(
                            yearMonth, iDCardNumber,workTeamSerialNumber)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 个人中心党员端-党员事务-随手拍
     *
     * @return
     */
    @Operation(summary = "小程序 个人中心党员端-党员事务-随手拍")
    @Parameters({
            @Parameter(name = "phone", description = "手机号"),
    })
    @GetMapping("/random/photo")
    @ResponseBody
    public AjaxResult getRandomPhoto(
            @RequestParam  String phone ,
            @RequestParam(required = false) String status,
            @RequestParam(required = false, defaultValue = "1") int pageNum,
    @RequestParam(required = false, defaultValue = "10") int pageSize) {
        try {
            return success(partyOrganizationActivityService
                    .getRandomPhoto(
                            phone,status,pageNum,pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }


    /**
     * 小程序 个人中心党员端-党员事务-随手拍-详情
     *
     * @return
     */
    @Operation(summary = "小程序 个人中心党员端-党员事务-随手拍-详情")
    @Parameters({
            @Parameter(name = "complaintId", description = "随手拍id"),
    })
    @GetMapping("/random/photo/detail")
    @ResponseBody
    public AjaxResult getRandomPhotoDetail(
            @RequestParam  String complaintId ) {
        try {
            return success(partyOrganizationActivityService
                    .getRandomPhotoDetail(
                            complaintId)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 获取所有党组织活动类型 json
     *
     * @return
     */
    @Operation(summary = "小程序 获取所有党组织活动类型 json")
    @Parameters({

    })
    @GetMapping("/getActivityTypeList")
    @ResponseBody
    public AjaxResult getActivityTypeList() {
        try {
            JSONObject result = new JSONObject();
            List<JSONObject> list = Lists.newArrayList();

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("title","全部");
            jsonObject.put("value","");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","党员大会");
            jsonObject.put("value","党员大会");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","支委会");
            jsonObject.put("value","支委会");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","党小组会");
            jsonObject.put("value","党小组会");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","党课");
            jsonObject.put("value","党课");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","主题党日");
            jsonObject.put("value","主题党日");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","双联系双报到");
            jsonObject.put("value","双联系双报到");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","民主生活会");
            jsonObject.put("value","民主生活会");
            list.add(jsonObject);

            jsonObject = new JSONObject();
            jsonObject.put("title","组织生活会");
            jsonObject.put("value","组织生活会");
            list.add(jsonObject);

            result.put("activityType",list);
            return success(result);
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }



    /**
     * 小程序 党员文件 类型列表
     * @return
     */
     @Operation(summary = "小程序 党员文件 类型列表")
    @Parameters({
            @Parameter(name = "partyMemberSerialNumber", description = "党员id"),
    })
    @GetMapping("/getMicroPartyMemberAttachmentTypeList")

    @ResponseBody
    public AjaxResult getMicroPartyMemberAttachmentTypeList(
            @RequestParam  String partyMemberSerialNumber
    ){
        return success(partyOrganizationService.getMicroPartyMemberAttachmentTypeList(partyMemberSerialNumber));
    }
    /**
     * 小程序 党员文件 列表
     * @return
     */
    @Operation(summary = "小程序 党员文件 列表")
    @Parameters({
            @Parameter(name = "partyMemberSerialNumber", description = "党员id"),
            @Parameter(name = "type", description = "文件类型"),
    })
    @GetMapping("/getMicroPartyMemberAttachmentList")

    @ResponseBody
    public AjaxResult getMicroPartyMemberAttachmentList(
            @RequestParam  String partyMemberSerialNumber,
            @RequestParam  String type
    ){
        return success(partyOrganizationService.getMicroPartyMemberAttachmentList(partyMemberSerialNumber,type));
    }

    /**
     * 小程序 签到管理
     *
     * @param formatDate
     * @return
     */
    @Operation(summary = "小程序 签到管理，查询支部下面的活动 根据不同的月份 YYYY-MM 和 党组织编号 获取三会一课列表和指标")
    @Parameters({
            @Parameter(name = "formatDate", description = "格式化的时间月份 YYYY-MM"),
            @Parameter(name = "partyOrganizationSerialNumber", description = "下拉选择的最底级的党组织，默认传漠河市党委"),
            @Parameter(name = "activityStatus", description = "活动状态"),
            @Parameter(name = "activityType", description = "活动类别"),
            @Parameter(name = "pageNum", description = "当前页数"),
            @Parameter(name = "pageSize", description = "每页条数")
    })
    @GetMapping("/activity/getSignUpManageList")
    @ResponseBody
    public AjaxResult getSignUpManageList(@RequestParam(required = false) String formatDate,
                                                     @RequestParam(required = false) String partyOrganizationSerialNumber,
                                                     @RequestParam(required = false) String activityStatus,
                                                     @RequestParam(required = false) String activityType,
                                                     @RequestParam(required = false, defaultValue = "1") int pageNum,
                                                     @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        try {
            List<String> activityTypeList = Lists.newArrayList();
            if (StringUtils.isEmpty(activityType)) {
                activityTypeList.add("党员大会");
                activityTypeList.add("党小组会");
                activityTypeList.add("支委会");
                activityTypeList.add("党课");
                activityTypeList.add("主题党日");
                activityTypeList.add("双联系双报到");
                activityTypeList.add("民主生活会");
                activityTypeList.add("组织生活会");
            } else {
                if (activityType.equals("党员大会")) {
                    activityTypeList.add("党员大会");
                }
                if (activityType.equals("党小组会")) {
                    activityTypeList.add("党小组会");
                }
                if (activityType.equals("支委会")) {
                    activityTypeList.add("支委会");
                }
                if (activityType.equals("党课")) {
                    activityTypeList.add("党课");
                }
                  if (activityType.equals("主题党日")) {
                    activityTypeList.add("主题党日");
                }
                  if (activityType.equals("双联系双报到")) {
                    activityTypeList.add("双联系双报到");
                }
                  if (activityType.equals("民主生活会")) {
                    activityTypeList.add("民主生活会");
                }
                  if (activityType.equals("组织生活会")) {
                    activityTypeList.add("组织生活会");
                }

            }

            if (StringUtils.isEmpty(formatDate)) {
                formatDate = DateFormatUtils.format(new Date(), "yyyy-MM");
            }
            if (ObjectUtils.isEmpty(pageNum) || pageNum == 0) {
                pageNum = 1;
            }
            if (ObjectUtils.isEmpty(pageSize) || pageSize == 0) {
                pageSize = 10;
            }
            return success(partyOrganizationActivityService
                    .getMicroPartyOrganizationActivityListByStatus
                            (formatDate,
                                    partyOrganizationSerialNumber,
                                    activityTypeList,
                                    activityStatus,
                                    "支部", pageNum, pageSize));
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 个人中心党员端-活动积分
     * @param iDCardNumber
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Operation(summary = "小程序 个人中心党员端-活动积分")
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号"),
    })
    @GetMapping("/activity/points")
    @ResponseBody
    public AjaxResult getActivityPoints(
            @RequestParam  String iDCardNumber ,
            @RequestParam(required = false, defaultValue = "1") int pageNum,
            @RequestParam(required = false, defaultValue = "10") int pageSize) {
        try {
            return success(partyOrganizationActivityService
                    .getActivityPoints(
                            iDCardNumber,pageNum,pageSize)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }

    /**
     * 小程序 工作队，根据身份证和工作队id获取成员编号
     * @param iDCardNumber
     * @return
     */
    @Operation(summary = "小程序 工作队，根据身份证和工作队id获取成员编号")
    @Parameters({
            @Parameter(name = "iDCardNumber", description = "身份证号"),
            @Parameter(name = "workTeamSerialNumber", description = "工作队id"),
    })
    @GetMapping("/work/team/member")
    @ResponseBody
    public AjaxResult getWorkTeamMember(
            @RequestParam  String iDCardNumber ,
            @RequestParam  String workTeamSerialNumber
            ) {
        try {
            return success(partyOrganizationActivityService
                    .getWorkTeamMember(
                            iDCardNumber,workTeamSerialNumber)
            );
        } catch (Exception e) {
            e.printStackTrace();
            logger.severe(e.getMessage());
            return error("程序错误请联系系统管理员");
        }
    }


}
